package com.th.supcom.pds.impl.service.internal.phamapply.chain;

import java.util.List;

import net.carefx.framework.exception.BusinessException;

import org.apache.commons.chain.impl.ChainBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

import com.th.supcom.pds.domain.pojo.InpPhamApplyMaster;
import com.th.supcom.pds.domain.vo.InpPhamApplyDetailVO;
import com.th.supcom.pds.impl.service.internal.phamapply.command.PhamDispenseContext;

/**
 * 住院摆药请领执行chain
 * 
 * @author leaqua@qq.com
 */
public class InpPhamDispenseServiceChain implements BeanFactoryAware
{
    private BeanFactory m_beanFactory;
    private PhamDispenseContext m_phamDispenseContext;

    public void setPhamDispenseContext (PhamDispenseContext phamDispenseContext)
    {
        m_phamDispenseContext = phamDispenseContext;
    }

    public void inpPhamDispense (List <InpPhamApplyDetailVO> applyList, InpPhamApplyMaster inpPhamApplyMaster, String operator, String dispensary)
    {
        m_phamDispenseContext.setInpPhamApplyMaster (inpPhamApplyMaster);
        m_phamDispenseContext.setOperator (operator);
        m_phamDispenseContext.setApplyDetailVOList (applyList);
        m_phamDispenseContext.setDispensary (dispensary);
        try
        {
            ChainBase chainBase = createChain ("inpPhamDispenseChain");
            chainBase.execute (m_phamDispenseContext);
        }
        catch (Exception exc)
        {
            throw new BusinessException (exc.getMessage (), exc);
        }
    }

    protected ChainBase createChain (String chainName)
    {
        return (ChainBase) this.m_beanFactory.getBean (chainName);
    }

    @Override
    public void setBeanFactory (BeanFactory beanFactory)
    {
        this.m_beanFactory = beanFactory;
    }

    /** 日志记录器. */
    public static final Logger s_logger = LoggerFactory.getLogger (InpPhamDispenseServiceChain.class);

    /** 公司版权信息. */
    public static final String copyright = "Copyright 2014, TH Supcom Corporation";

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";

    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";

}
